package com.basketball.gym.controller;


import com.basketball.gym.pojo.Calendar;
import com.basketball.gym.pojo.ResponseData;
import com.basketball.gym.service.CalendarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 赵肖云
 * @since 2021-03-26
 */
@Api(tags = "日程管理")
@RestController
@RequestMapping("/gym/calendar")
public class CalendarController {
    @Autowired
    private CalendarService calendarService;

    @ApiOperation("查询球馆日程")
    @GetMapping
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "date", value = "时间[yyyy-MM-dd]", dataType = "Date", defaultValue = "2019-03-14"),
            @ApiImplicitParam(paramType = "query", name = "timeId", value = "时间ID", dataType = "Integer", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "type", value = "类型", dataType = "Short", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "state", value = "状态", dataType = "Short", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "courtId", value = "球场ID", dataType = "Integer", defaultValue = "1")
    })
    public ResponseData<List<Calendar>> getGymCalendar(@ApiIgnore Calendar calendar) {
        return calendarService.getGymCalendar(calendar);
    }

    @ApiOperation("管理员查询球馆日程")
    @PreAuthorize("hasAnyRole('admin','superAdmin')")
    @GetMapping("/admin")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "date", value = "时间[yyyy-MM-dd]", dataType = "Date", defaultValue = "2019-03-14"),
            @ApiImplicitParam(paramType = "query", name = "timeId", value = "时间ID", dataType = "Integer", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "type", value = "类型", dataType = "Short", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "state", value = "状态", dataType = "Short", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "courtId", value = "球场ID", dataType = "Integer", defaultValue = "1")
    })
    public ResponseData<List<Calendar>> adminGetGymCalendar(@ApiIgnore Calendar calendar) {
        return calendarService.adminGetGymCalendar(calendar);
    }

    @ApiOperation("修改场馆状态")
    @PreAuthorize("hasAnyRole('admin','superAdmin')")
    @PutMapping
    public ResponseData<Object> updateCalendarState(@Validated(Calendar.update.class) @RequestBody Calendar calendar) {
        return calendarService.updateCalendarState(calendar);
    }

}

